﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace RenShiKaoQin
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TKQEmployee kqemployee = null;
            bool IsKQY = false;
            if (Session["KQEmployee"] == null)
            {
                hrdbEntities ent = new hrdbEntities();
                var t = from temp in ent.TKQEmployees where temp.FEmployeeID.Equals(Page.User.Identity.Name) select temp;
                if (t.Any())
                {
                    kqemployee = t.Single();
                    Session["KQEmployee"] = kqemployee;
                }
                var t1 = from temp1 in ent.TDictDepts where temp1.FKQOperator.Equals(Page.User.Identity.Name) && temp1.FKQFlag == true select temp1;
                if (t1.Any())
                {
                    Session["IsKQY"] = true;
                    IsKQY = true;
                }
                else
                {
                    var t2 = from temp2 in ent.TDictDepts where temp2.FKQShenHe.Equals(Page.User.Identity.Name) && temp2.FKQFlag == true select temp2;
                    if (t2.Any())
                    {
                        Session["IsKQY"] = true;
                        IsKQY = true;
                    }
                    else
                    {
                        Session["IsKQY"] = false;
                        IsKQY = false;
                    }
                }
                ent.Dispose();
            }
            else
            {
                kqemployee = (TKQEmployee)Session["KQEmployee"];
                IsKQY = (bool)Session["IsKQY"];
            }
            
            string qj = Request.ApplicationPath;
            if (Request.Form["Term"]=="QXMenu")
            {
                if(IsKQY)Response.Write("<li><a href='"+qj+"/Account/KQForm.aspx'>科室管理</a></li>");
                if (kqemployee.IsLeader) Response.Write("<li><a href='" + qj + "/Account/LeaderForm.aspx'>领导查看</a></li>");
                if (kqemployee.IsExaminant) Response.Write("<li><a href='" + qj + "/Account/SPForm.aspx'>请假审批</a></li>");
                if (kqemployee.IsChecker) Response.Write("<li><a href='" + qj + "/Account/FHForm.aspx'>请假复核</a></li>");
                if (kqemployee.IsMExaminant) Response.Write("<li><a href='" + qj + "/Account/MSPForm.aspx'>会议初审</a></li>");
                if (kqemployee.IsMChecker) Response.Write("<li><a href='" + qj + "/Account/MFHForm.aspx'>会议复审</a></li>");
                if (kqemployee.IsStudyManager) Response.Write("<li><a href='" + qj + "/Account/StudyForm.aspx'>学习审批</a></li>");
                if (kqemployee.IsZNGL) Response.Write("<li><a href='" + qj + "/Account/ZNGLForm.aspx'>职能管理</a></li>");
                if (kqemployee.IsAdmin) Response.Write("<li><a href='" + qj + "/Account/GLForm.aspx'>系统设置</a></li>");
                Response.End();
            }
        }

        protected void lbtLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Session.Clear();
            Session.Abandon();
            Response.Redirect("~/Account/Guide.aspx");
        }
    }
}
